﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class ExportésForm : Form
    {
        public List<Image_Message_exporté> imageexporte = new List<Image_Message_exporté>();

        public ExportésForm()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboBoxdis.DataSource = context.Distinataires;
            comboBoxdis.DisplayMember = "Nom_Distinataire";
        }

        private void btnajouter_Click(object sender, EventArgs e)
        {
            if (ValidateChildren(ValidationConstraints.Enabled))
            {
                RAMEDEntities1 Context = new RAMEDEntities1();
                Exportés expo = new Exportés();
                expo.Num_message = utitlitaire.CasterString(txtobjet.Text);
                expo.Date_envoi = dateTimePickerdateenv.Value;
                expo.Objet = txtnombre.Text;
                expo.id_Distinataire = ((Distinataire)comboBoxdis.SelectedValue).id_Distinataire;
                foreach (Image_Message_exporté imaexp in imageexporte)
                    expo.Image_Message_exporté.Add(imaexp);
                Context.Exportés.AddObject(expo);
                Context.SaveChanges();
                this.Dispose();
            }
        }

        private void txtnombre_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtnombre_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderNombre("Saisissez un nombre valide", txtobjet, e, errorProvider1);

        }

        private void txtdis_TextChanged(object sender, EventArgs e)
        {

        }

       
        private void txtobjet_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtobjet_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Objet est obligatoire", txtnombre, e, errorProvider1);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void ajouterImageButton_Click(object sender, EventArgs e)
        {
            Imageviewerexportes imageViewerexportes = new Imageviewerexportes();
            imageViewerexportes.exportesf = this;
            imageViewerexportes.Show();
        }
    }
}
